from django.urls import reverse
from rest_framework.test import APIClient
from video.models import Videos
from django.test import TestCase
from user.models import UserProfile
from favor.models import Favor
from follow.models import Follow

class TestFollowViewSet(TestCase):
    def setUp(self):
        self.client = APIClient()
        self.user1 = UserProfile.objects.create_user(id=1, username='testuser1', password='123456456')
        self.user2 = UserProfile.objects.create_user(id=2, username='testuser2', password='123456456')
        self.user3 = UserProfile.objects.create_user(id=3, username='testuser3', password='123456456')
        self.follow1 = Follow.objects.create(foid=1, fan=self.user1, mup=self.user2)
        self.follow1 = Follow.objects.create(foid=2, fan=self.user1, mup=self.user3)
        self.follow1 = Follow.objects.create(foid=3, fan=self.user2, mup=self.user3)

    def test_get_follow_count_exists(self):
        url = reverse('follow-count', kwargs={'mup':3, 'fan':1})
        response = self.client.get(url)
        data = response.json()
        self.assertEqual(data['fan_count'], 2)

    def test_get_follow_count_not_exists(self):
        url = reverse('follow-count', kwargs={'mup':1, 'fan':1})
        response = self.client.get(url)
        data = response.json()
        self.assertEqual(data['fan_count'], 0)

    def test_get_follow_count_followed(self):
        url = reverse('follow-count', kwargs={'mup':3, 'fan':1})
        response = self.client.get(url)
        data = response.json()
        self.assertEqual(data['is_fan'], True)

    def test_get_follow_count_not_followed(self):
        url = reverse('follow-count', kwargs={'mup':1, 'fan':3})
        response = self.client.get(url)
        data = response.json()
        self.assertEqual(data['is_fan'], False)

    def test_get_my_follow_as_fan(self):
        url = reverse('get_my_follow', kwargs={'user':1, 'num':2, 'from':0, 'op':0})
        responce = self.client.get(url)
        data = responce.json()
        self.assertEqual(data['count'], 2)

    def test_get_my_follow_as_fan_not_exists(self):
        url = reverse('get_my_follow', kwargs={'user':3, 'num':1, 'from':0, 'op':0})
        responce = self.client.get(url)
        data = responce.json()
        self.assertEqual(data['count'], 0)

    def test_get_my_follow_as_up(self):
        url = reverse('get_my_follow', kwargs={'user':3, 'num':2, 'from':0, 'op':1})
        responce = self.client.get(url)
        data = responce.json()
        self.assertEqual(data['count'], 2)

    def test_get_my_follow_as_up_not_exists(self):
        url = reverse('get_my_follow', kwargs={'user':1, 'num':1, 'from':0, 'op':1})
        responce = self.client.get(url)
        data = responce.json()
        self.assertEqual(data['count'], 0)

